#!/bin/sh
AppName="Alcatel X500 Connection Manager"
itemtoaddA="/Applications/${AppName}.app"
itemtoadd="${AppName}.app"
#application_check1=`sudo -u $SUDO_USER defaults read com.apple.dock persistent-apps | grep -w _CFURLString | awk 'BEGIN { FS = "\"" } ; { print $4 }' | grep -x "${itemtoadd}"`
#application_check2=`sudo -u $SUDO_USER defaults read com.apple.dock persistent-apps | grep -w _CFURLString | awk 'BEGIN { FS = "\"" } ; { print $4 }' | grep -x "${itemtoadd}/"` 

application_check1=`sudo -u $USER defaults read com.apple.dock persistent-apps | grep -w _CFURLString | awk 'BEGIN { FS = "\"" } ; { print $4 }' | grep  "${itemtoadd}"`
application_check2=`sudo -u $USER defaults read com.apple.dock persistent-apps | grep -w _CFURLString | awk 'BEGIN { FS = "\"" } ; { print $4 }' | grep  "${itemtoadd}/"`


rm /System/Library/Extensions.kextcache
kextcache -k /System/Library/Extensions
rm -Rf /System/Library/Caches
touch /System/Library/Extensions

if [ "${application_check1}" != "" ] || [ "${application_check2}" != "" ] ; then
    #echo "WARNING! :  This application is in the dock"
    # This application is in the dock
exit 0

else
    sudo -u $USER defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>${itemtoaddA}</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"   
killall "Dock"

fi

exit 0

